/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-10-10 18:45:54
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-10 19:34:15
 * @FilePath: /GateServer/src/redis/redisconnectionpool.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#pragma once
#include <condition_variable>
#include <cstddef>
#include <hiredis/hiredis.h>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include "atomic"
namespace Yizhi {
    class  RedisConnectionPool{

        public:
        RedisConnectionPool(std::string host,int port,std::string psw,size_t size=1);
        ~RedisConnectionPool();
        redisContext*GetConnection();
        void ReturnConnection(redisContext*);
        void close();

        private:
        redisContext *CreateConnection();
        private:
        std::string m_host;
        int m_port;
        std::string m_psw;
        size_t m_size;
        std::queue<redisContext*> m_connections;
        std::mutex m_mutex;
        std::condition_variable m_cond;
        std::atomic<bool> m_stop{false};
    };
}